<template>
  <div id="volume">
    <!-- 音量图标 -->
    <div class="icon" @click="openOrCloseVoice">
      <i v-show="hasVoice" class="iconfont icon-yinliang"></i>
      <i v-show="!hasVoice" class="iconfont icon-guanbiyinliang"></i>
    </div>
    <!-- 控制音量 -->
    <div class="volume-control">
      <el-slider
        v-model="volume"
        :show-tooltip="false"
        :disabled="!hasVoice"
        :class="{ disabled: !hasVoice }"
        @input="handleVolumeInput"></el-slider>
    </div>
  </div>
</template>

<script>
export default {
  name: 'FooterVolume',
  data () {
    return {
      hasVoice: true,
      volume: 50
    }
  },
  created () {
    console.log(this.$audio.volume)
  },
  methods: {
    // 1. 打开或者关闭声音
    openOrCloseVoice () {
      this.hasVoice = !this.hasVoice
      this.$audio.muted = !this.hasVoice
    },
    // 2. 处理声音滑块
    handleVolumeInput () {
      this.$audio.volume = this.volume / 100
    }
  }
}
</script>

<style scoped lang="less">
#volume {
  overflow: hidden;
  display: flex;
  align-items: center;
  .icon {
    position: relative;
    width: 25px;
    cursor: pointer;
    > i {
      font-size: 18px;
      position: absolute;
      transform: translateY(-50%);
    }
  }
  .volume-control {
    flex: 1;
    padding-right: 8px;
    padding-left: 3px;
  }
}
</style>

<style lang="less">
#volume {
  .el-slider {
    .el-slider__runway {
      background-color: #c2c2c4;
      box-shadow: 0 0 2px 0 #c2c2c4;
      .el-slider__bar {
        background-color: var(--base--color);
      }
      .el-slider__button-wrapper {
        .el-slider__button {
          border: 2px solid #bfbfbf;
          position: relative;
          &::after {
            content: "";
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 4px;
            height: 4px;
            border-radius: 50%;
            background-color: var(--base--color);
          }
        }
      }
    }
    &.disabled {
      .el-slider__bar {
        background-color: #c2c2c4;
      }
    }
  }
}
</style>
